#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

//https://leetcode.cn/problems/subtree-of-another-tree/
struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    
};

bool SameTree(struct TreeNode* p1, struct TreeNode* p2)
{
    if (p1 == NULL && p2 == NULL)
        return true;
    else if (p1 != NULL && p2 != NULL) {
        if (p1->val == p2->val)
            return SameTree(p1->left, p2->left) && SameTree(p1->right, p2->right);
        else
            return false;
    }
    else
        return false;
}

bool isSubtree(struct TreeNode* root, struct TreeNode* subRoot) {
    if (root == NULL)
        return false;
    if (SameTree(root, subRoot))
        return true;
    return isSubtree(root->left, subRoot) || isSubtree(root->right, subRoot);
}